package com.zero.apifox.common;


import lombok.Data;

/**
 * 统一返回工具类
 * @param <T>
 */
@Data
public class ResultBean<T> {
    /**
     * 状态码
     */
    private int code;
    /**
     * 业务状态码
     */
    private String stateCode;
    /**
     * 业务消息
     */
    private String message;
    /**
     * 响应结果集
     */
    private T data;
    public ResultBean() {
    }
    public ResultBean(ResultStateEnum resultStateEnum) {
        this.code = resultStateEnum.getCode();
        this.stateCode = resultStateEnum.getStateCode();
        this.message = resultStateEnum.getMessage();
    }
    public ResultBean(ResultStateEnum resultStateEnum, T data) {
        this.code = resultStateEnum.getCode();
        this.stateCode = resultStateEnum.getStateCode();
        this.message = resultStateEnum.getMessage();
        this.data = data;
    }
    public ResultBean(int code, String stateCode, String message) {
        this.code = code;
        this.stateCode = stateCode;
        this.message = message;
    }
    public ResultBean(int code, String stateCode, String message, T data) {
        this.code = code;
        this.stateCode = stateCode;
        this.message = message;
        this.data = data;
    }
    public static <T> ResultBean<T> success() {
        return new ResultBean<>(ResultStateEnum.SUCCESS);
    }
    public static <T> ResultBean<T> success(T data) {
        return new ResultBean<>(ResultStateEnum.SUCCESS, data);
    }
    public static <T> ResultBean<T> fail() {
        return new ResultBean<>(ResultStateEnum.FAIL);
    }
    public static <T> ResultBean<T> fail(String message) {
        return new ResultBean<>(ResultStateEnum.FAIL.getCode(), ResultStateEnum.FAIL.getStateCode(), message);
    }
    public static <T> ResultBean<T> fail(ResultStateEnum state) {
        return new ResultBean<>(state);
    }
    public static <T> ResultBean<T> fail(ResultStateEnum state, String message) {
        return new ResultBean<>(state.getCode(), state.getStateCode(), message);
    }
}
